<?php

namespace pmvc\mvc;

use pmvc\io\IOUtil;

class UploadedFile {

	private $name;
	private $type;
	private $size;
	private $tempFileName;
	private $errorCode;

	public function __construct($file) {
		$this->name			= isset($file["name"]) ? $file["name"] : null;
		$this->type			= isset($file["type"]) ? $file["type"] : null;
		$this->size			= isset($file["size"]) ? $file["size"] : null;
		$this->tempFileName	= isset($file["tmp_name"]) ? $file["tmp_name"] : null;
		$this->errorCode	= isset($file["error"]) ? $file["error"] : -1;
	}

	public function getName() {
		return $this->name;
	}

	public function getMimeType() {
		return $this->type;
	}

	public function getSize() {
		return $this->size;
	}

	public function getTempFileName() {
		return $this->tempFileName;
	}

	public function getErrorCode() {
		return $this->errorCode;
	}

	public function isError() {
		return $this->errorCode != 0;
	}

	public function openStream($mode, $contenxt=NULL) {
		return IOUtil::openFile($this->tempFileName, $mode, FALSE, $context);
	}

	public function move($destination) {
		return move_uploaded_file($this->tempFileName, $destination);
	}
	
}

?>